#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;
void solve()
{
    int n, m;
    cin >> n >> m;
    set<string> a;
    for (int i = 0; i < n; i++)
    {
        string z;
        cin >> z;
        a.insert(z);
    }
    set<string> s;
    vector<pair<string, string>> p;
    while (m--)
    {
        int op;
        cin >> op;
        if (op == 1)
        {
            string x, y;
            cin >> x >> y;
            s.insert(x);
            s.insert(y);
            p.push_back({x, y});
        }
        else if (op == 2)
        {
            string x, y;
            cin >> x >> y;
            for (auto i : p)
            {
                if (i.fi == x && i.se == y || i.fi == y && i.se == x)
                {
                    auto it1 = s.find(x);
                    auto it2 = s.find(y);
                    if (it1 != s.end() && it2 != s.end())
                        cout << 1 << endl;
                    else
                        cout << 0 << endl;
                }
            }
        }
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    int T = 1;
    // cin>>T;
    while (T--)
    {
        solve();
    }
    return 0;
}